package com.wyl.mine.unique.evaluate

import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.flyco.tablayout.listener.OnTabSelectListener
import com.google.android.material.tabs.TabLayout
import com.wuhenzhizao.titlebar.widget.CommonTitleBar
import com.wyl.libbase.base.BindingActivity
import com.wyl.libbase.binding.recyclerview.RecyclerViewDivider
import com.wyl.libbase.extend.setDrawableBottom
import com.wyl.libbase.extend.toast
import com.wyl.mine.R
import com.wyl.mine.databinding.EvaluateMineActivityBinding
import io.ditclear.bindingadapter.SingleTypeAdapter
import kotlinx.android.synthetic.main.assets_activity.*
import kotlinx.android.synthetic.main.evaluate_mine_activity.*
import kotlinx.android.synthetic.main.evaluate_mine_activity.titleBar
import kotlinx.android.synthetic.main.evaluate_title.*
import kotlinx.android.synthetic.main.evaluate_title.tab
import kotlinx.android.synthetic.main.evaluate_title.view.*
import kotlinx.android.synthetic.main.evaluate_title.view.tab
import kotlinx.android.synthetic.main.wallet_list_item.*
import org.koin.android.viewmodel.ext.android.viewModel

class EvaluateMineActivity : BindingActivity<EvaluateMineActivityBinding>() {
    private val viewModel by viewModel<EvaluateMineViewModel>()

    private val titles = arrayOf("发出的评价", "收到的评价")

    override fun getLayoutId(): Int = R.layout.evaluate_mine_activity

    override fun initView() {
        binding.vm = viewModel

        titleBar.apply {
            setListener { _, action, _ ->
                when (action) {
                    CommonTitleBar.ACTION_LEFT_BUTTON -> onBackPressed()
                    else -> {
                    }
                }
            }
        }

        val tabLayout = titleBar.centerCustomView.tab
        tabLayout.setTabData(titles)
        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                toast("ss $position")
            }

            override fun onTabReselect(position: Int) {

            }
        })


        binding.include.recyclerView.apply {
            layoutManager = LinearLayoutManager(context)
            adapter = mAdapter
            addItemDecoration(mDivider)
        }

    }

    private val mAdapter by lazy {
        SingleTypeAdapter(this, R.layout.evaluate_mine_item, viewModel.dataSource)
    }

    private val mDivider by lazy {
        RecyclerViewDivider(this, LinearLayoutManager.VERTICAL)
    }

    override fun loadData() {
        viewModel.refresh()
        viewModel.error.observe(this, Observer { toast(it) })
    }


}
